package com.springcloud.demo.controller;

import com.springcloud.demo.entities.Dept;
import com.springcloud.demo.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptController_Consumer {
    /**
     *    Feign通过接口的方法调用Rest服务（之前是Ribbon+RestTemplate），
     * 该请求发送给Eureka服务器（http://MICROSERVICECLOUD-DEPT/dept/list）,
     * 通过Feign直接找到服务接口，由于在进行服务调用的时候融合了Ribbon技术，所以也支持负载均衡作用。
     */
   @Autowired
   private DeptClientService service;

    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept){
        return service.add(dept);
    }
    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable Long id){
        return service.get(id);
    }
    @RequestMapping("consumer/dept/list")
    public List<Dept> list(){
        return service.list();
    }

}
